// ****************************************************************************
// @File: SmartPtrManager.h
//
// PURPOSE: A tool class to do the actual GC work
// AUTHOR:  Zj Ai
//
// NOTES: 
//     
// HISTORY:
//
//   ------ Zj Ai  05/07/2012 creating the file
//
// @EndHeader@
// ****************************************************************************

#include "stdafx.h"
#include "SmartPtrManager.h"

class CGcTool
{
public:
	// classify the ptrs from userReachable and embedded, this is the only two possible
	static void ClassifySmartPtrs(
		list<LinkNode*>& needGcPtrs, 
		list<LinkNode*>& userReachablePtrs, 
		list<LinkNode*>& embeddedPtrs);

	// mark the ptrs, and return the useless ptrs, ie, the return list needs to delete
	static void Mark( 
		list<LinkNode*>& userReachablePtrsList, 
		list<LinkNode*>& embeddedPtrsList, 
		list<LinkNode*>& usingPtrsList);

	// collect the garbage, the return value is collected objects	
	static UINT DoGcWork(list<LinkNode*>& embeddedPtrList);

private:
	static void MarkUsingPtrs( LinkNode *ptr, list<LinkNode*>& embeddedPtrList, list<LinkNode*>& receiveList);
};